﻿using Assets.Script.Human.Player;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.TextCore.LowLevel;

public class PlayerBuffManager : MonoBehaviour
{
    [SerializeField]
    public Dictionary<string,PlayerBuff> buffs { get; } = new Dictionary<string, PlayerBuff>();

    PlayerBody playerBody;

    public void Init(PlayerBody playerBody)
    {
        this.playerBody = playerBody;
    }

    private void Start()
    {
        
        playerBody = GetComponent<PlayerBody>();
        //GetBuff(new TestTimeBuff());
    }

    private void Update()
    {
        foreach (var item in buffs.Values)
        {
            item.Update();
        }
    }

    public void GetBuff(PlayerBuff buff)
    {
        if (buffs.ContainsKey(buff.Name))
        {
            buffs[buff.Name].OnGetSecond();
        }
        else
        {
            buffs.Add(buff.Name, buff);
            buff.OnGetFirst(playerBody);
        }
        
    }

    public void RemoveBuff(PlayerBuff buff)
    {
        buff.OnEnd();
        buffs.Remove(buff.Name);
    }

    

}
